{% extends "admin/base.html" %}
{% block content %}
    {{ super() }}
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
                <div class="layui-form-item">
                    {% if provinces %}
                        <div class="layui-inline">
                            <label class="layui-form-label">省份</label>
                            <div class="layui-input-inline">
                                <select name="province" id="zw_province" lay-filter="provinceSelect">
                                    <option value="0">请选择</option>
                                    {% for province in provinces %}
                                        <option value="{{ province }}">{{ province }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                    {% endif %}
                    {% if cities %}
                        <div class="layui-inline">
                            <label class="layui-form-label">城市</label>
                            <div class="layui-input-inline">
                                <select name="city" id="zw_city">
                                    <option value="0">请选择</option>
                                    {% for city in cities %}
                                        <option value="{{ city.id }}">{{ city.dd_name }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                    {% endif %}
                    <div class="layui-inline">
                        <label class="layui-form-label">公司性质</label>
                        <div class="layui-input-inline">
                            <select name="gsxz" id="zw_gsxz">
                                <option value="0">请选择</option>
                                {% for item in gsxz %}
                                    <option value="{{ item.id }}">{{ item.gsxz_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司规模</label>
                        <div class="layui-input-inline">
                            <select name="gsgm" id="zw_gsgm">
                                <option value="0">请选择</option>
                                {% for item in gsgm %}
                                    <option value="{{ item.id }}">{{ item.gsgm_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">学历</label>
                        <div class="layui-input-inline">
                            <select name="xl" id="zw_xl">
                                <option value="0">请选择</option>
                                {% for item in xl %}
                                    <option value="{{ item.id }}">{{ item.xl_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">工作经验</label>
                        <div class="layui-input-inline">
                            <select name="gzjy" id="zw_gzjy">
                                <option value="0">请选择</option>
                                {% for item in gzjy %}
                                    <option value="{{ item.id }}">{{ item.gzjy_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司行业</label>
                        <div class="layui-input-inline">
                            <select name="gshy" id="zw_gshy">
                                <option value="0">请选择</option>
                                {% for item in gshy %}
                                    <option value="{{ item.id }}">{{ item.gshy_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">大分类</label>
                        <div class="layui-input-inline">
                            <select name="zwlb_big" id="zw_zwlb_big" lay-filter="zwlbBigSelect">
                                <option value="0">请选择</option>
                                {% for item in zwlb_big %}
                                    <option value="{{ item.id }}">{{ item.zwlb_big_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">小分类</label>
                        <div class="layui-input-inline">
                            <select name="zwlb" id="zw_zwlb">
                                <option value="0">请选择</option>
                                {% for item in zwlb %}
                                    <option value="{{ item.id }}">{{ item.zwlb_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn layuiadmin-btn-list" lay-submit=""
                                lay-filter="LAY-app-contlist-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"
                               style="position:initial"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                </div>
                <table id="zp-table-list" lay-filter="zp-table-list"></table>
            </div>
        </div>
    </div>
    </div>
{% endblock %}
{% block script %}
    <script>
        layui.use(['jquery', 'layer', 'element', 'table', 'form'], function () {
            var $ = layui.jquery, i = layui.view,
                element = layui.element,
                layer = layui.layer, table = layui.table, form = layui.form;
            table.render({
                elem: "#zp-table-list",
                url: "{{ url_for('admin_get_list') }}",
                cols: [[
                    {field: 'id', title: 'ID'}
                    , {field: 'zwmc_name', title: '职位名'}
                    , {field: 'gsmc_name', title: '公司名'}
                    , {field: 'dd_name', title: '地点'}
                    , {field: 'gsxz_name', title: '公司性质'}
                    , {field: 'gsgm_name', title: '公司规模'}
                    , {field: 'xl_name', title: '学历'}
                    , {field: 'gzjy_name', title: '工作经验'}
                    , {field: 'gshy_name', title: '公司行业'}
                    , {field: 'zwlb_name', title: '职位类别'}
                    , {field: 'zwlb_big_name', title: '大分类'}
                    , {field: 'min_zwyx', title: '最低薪资'}
                    , {field: 'max_zwyx', title: '最高薪资'}, {
                        title: "操作",
                        align: "left",
                        fixed: "right",
                        toolbar: "#table-content-list"
                    }]],
                page: 1,
                limit: 10,
                limits: [10, 15, 20],
                text: "对不起，加载出现异常！"
            });
            //监听搜索
            form.on('submit(LAY-app-contlist-search)', function (data) {
                var field = data.field;
                var index=layer.load(3);
                //执行重载
                table.reload('zp-table-list', {
                    where: field,
                    done: function (res, curr, count) {
                        layer.close(index);
                    }
                });
            });
            table.on("tool(zp-table-list)", function (t) {
                var n = t.data;
                "del" === t.event ? layer.confirm("确定删除此记录？", function (e) {
                    layer.close(e);
                    $.ajax({
                        url: "{{ url_for('admin_del_list') }}",
                        data: {'id': n.id},
                        success: function (returnData) {
                            if (returnData.status == 1) {
                                table.reload('zp-table-list');
                                layer.msg('已删除');
                                t.del()
                            }
                            else {
                                layer.msg(returnData.info);
                            }
                        }
                    });
                }) : "edit" === t.event && layer.open({
                    type: 2,
                    title: "编辑记录",
                    shadeClose: true,
                    shade: 0.8,
                    anim: 2,
                    area: ["980px", "400px"],
                    id: "LAY-popup-content-edit",
                    content: "/admin/edit/list/" + n.id,
                    end: function (index, layero) {
                        table.reload('zp-table-list');
                    }
                })
            });
            // 省份
            form.on('select(provinceSelect)', function (data) {
                if (data.value != 0) {
                    $.ajax({
                        url: '/get/city/list',
                        data: {'province': data.value},
                        dataType: 'json',
                        success: function (returnData) {
                            var city_list = '<option value="0">请选择</option>';
                            $.each(returnData, function (index, item) {
                                city_list = city_list + '<option value="' + item.id + '">' + item.dd_name + '</option>'
                            });
                            $("#zw_city").html(city_list);
                            form.render('select')
                        }
                    });
                }
            });
            // 大分类
            form.on('select(zwlbBigSelect)', function (data) {
                if (data.value != 0) {
                    $.ajax({
                        url: '/get/zwlb/list',
                        data: {'zwlb': data.value},
                        dataType: 'json',
                        success: function (returnData) {
                            var zwlb_list = '<option value="0">请选择</option>';
                            $.each(returnData, function (index, item) {
                                zwlb_list = zwlb_list + '<option value="' + item.id + '">' + item.zwlb_name + '</option>'
                            });
                            $("#zw_zwlb").html(zwlb_list);
                            form.render('select')
                        }
                    });
                }
            });
            $('.layui-nav-item').removeClass('layui-this');
            $('#admin_list').addClass('layui-this');
        });

    </script>
    <script type="text/html" id="table-content-list">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </script>
{% endblock %}